//
//  MaoLing.swift
//  jhf
//
//  Created by Mac on 2021/09/28 17:40:08.
//  Copyright © 2021 jhf. All rights reserved.
//
import Foundation
import UIKit
import Moya
import CryptoSwift
import SwiftyJSON
import CooperSwift

// LogPlugin(),
// SpinnerPlugin()
// EncryptPlugin()
// RequestAlertPlugin
// ResultPlugin()

let MaoLingProvider = MoyaProvider<MaoLing>(plugins: [SpinnerPlugin(), LogPlugin()])

   
public enum MaoLing {
     // 获取客服信息
     case appAppgetserviceinfo

     // 获取用户信息
     /// faccid 用户accid string ❤️
     case appAppgetuserinfo(String)

     // 验证手机号
     /// code 验证码 string ❤️
     case appCheckmobile(String)

     // 验证密码
     /// password 用户密码 string ❤️
     case appCheckpassword(String)

     // 获取登录用户信息
     case appGetmyinfo

     // 获取短信验证码
     /// mobile 手机号码 string ❤️
     case appGetsmscode(String)

     // 获取最新IOS版本信息
     case appIosversionGetlatestapkinfo

     // 登录
     /// mobile 手机号码 string ❤️
     /// password 密码 string ❤️
     case appLogin(String, String)

     // 使用accid登录
     /// accid 用户accid string ❤️
     case appLoginbyaccid(String)

     // 群发助手鉴权
     case appQunfaauth

     // 用户注册
     case appRegister

     /// 用户搜索
     /// name 关键字 string
     /// page 当前页 ref ❤️
     /// limit 每页显示的数据条数 ref ❤️
     case appSearchuserlist(String?, Int, Int)

     // 获取最新安卓版本信息
     case appTbapkversionGetlatestapkinfo

     // 个人设置
     /// avatar avatar file
     /// operation 设置类型;<br/> 1：修改头像（上传文件key：avatar） <br/>2：修改昵称；nickName <br/>3：修改性别；sexy（男/女）<br/>4：修改猫灵ID；batId（猫灵ID）<br/>5:修改手机号;code(验证码)；mobile（手机号）<br/>6：修改密码；oldPassword（旧密码）；password（新密码）<br/>7：设置隐私模式；privateMode（1/2）<br/>8：添加我为好友时需要验证，1:需要；0:不需要；needCheck（0/1）<br/>9：是否可以通过手机号查询;phoneSearch(0/1)<br/>10：是否可以通过app号搜索，1:可以；0:不可以;appSearch(0/1)<br/>11：是否可以通过名片添加，1:可以；0:不可以;identitySearch(0/1)<br/>14：是否可以通过二维码添加，1:可以；0:不可以;qrSearch(0/1)<br/>12：修改个性签名;值放在signature<br/>15：修改字体大小;值放在fontSize<br/>13：修改地区;值放在region ref ❤️
     case appUserinfosetting(Data?, Int)

     // 关于猫灵
     case appWaaboutusAppqueryaboutus

     // 获取隐私/用户协议
     /// type 1：用户协议；2：隐私说明 ref ❤️
     case appWaagreementGetuseragreement(Int)

     // 新增收藏
     /// file file file
     /// type 收藏内容类型：1:文字；2:语音；3:图片；4:视频；5：文件 ref ❤️
     /// targetUserAccid 目标用户accid string
     case appWafavoritemsgAddfavoritemsg(Data?, Int, String?)

     // 删除收藏
     /// id 收藏内容标识；多个使用英文逗号分开 string ❤️
     case appWafavoritemsgDeletefavoritemsg(String)

     // 我的收藏列表
     /// type 收藏类型；不传查所有;1:文字；2:语音；3:图片；4:视频；5：文件 ref
     case appWafavoritemsgMyfavoritelist(Int?)

     // 好友管理
     /// operation 操作类型:<br/>1:设置好友备注信息<br/>2:删除好友<br/>3：好友置顶 ref ❤️
     /// alias 好友备注 string ❤️
     /// falias 对方用户accid string ❤️
     /// type 1：设置置顶；2：取消置顶 ref ❤️
     case appWafriendsAppmanagefriends(Dictionary<String, Any>)

     // 置顶好友列表
     case appWafriendsGettopfriends

     // 发布朋友圈
     /// file file array
     /// content 文字内容 string ❤️
     case appWafriendszoneAddfriendszone(Array<Data>?, String)

     // 评论朋友圈、回复朋友圈
     /// zoneId 朋友圈标识 integer ❤️
     /// content 评论/回复内容 string ❤️
     /// targetUserId 被回复人，评价朋友圈时该值可不传 integer
     case appWafriendszoneAddzonecomment(Int, String, Int?)

     // 删除朋友圈内容
     /// zoneId 朋友圈内容标识 integer ❤️
     case appWafriendszoneDeletemyzone(Int)

     // 我发布的朋友圈清单
     /// page 当前页 ref ❤️
     /// limit 每页显示的数据条数 ref ❤️
     case appWafriendszoneGetmyzonelist(Int, Int)

     // 我的朋友圈
     /// page 当前页 ref ❤️
     /// limit 每页显示的数据条数 ref ❤️
     case appWafriendszoneGetzonelist(Int, Int)

     // 朋友圈点赞/取消点赞
     /// zoneId 朋友圈标识 integer ❤️
     /// type 1：点赞 2：取消点赞 ref ❤️
     case appWafriendszoneLikeorcancelzone(Int, Int)

     // 指定朋友圈详情
     /// zoneId 朋友圈标识 integer ❤️
     case appWafriendszoneQueryzonedetail(Int)

     // 小助手清单
     case appWahelperHelperlist

     // 获取禁言列表
     /// groupId 群组tid integer ❤️
     case appWahuhighgroupAppgetmutelist(Int)

     // SDK创建群成功后需要调用该接口
     /// tid 云信群组tid string ❤️
     case appWahuhighgroupCreategroupcallback(String)

     // 创建群聊
     /// file file file
     /// userIds userId，多个使用英文逗号拼接 string ❤️
     /// tname 群组名称 string ❤️
     /// anonymous 1：匿名群聊 2：非匿名群聊 ref ❤️
     case appWahuhighgroupCreatenewgroup(Dictionary<String, Any>)

     // 置顶群组列表
     case appWahuhighgroupGettopgroups

     // 扫码进群
     /// groupId 群组tid；不是主键 string ❤️
     case appWahuhighgroupInviteuserbyqrcode(String)

     // 群管理
     /// xxxxxx file file
     /// groupId 群组tid integer ❤️
     /// operation 操作类型：<br/>1：设置管理员<br/>2:群组禁言，普通成员不能发送消息，创建者和管理员可以发送消息<br/>3:指定用户禁<br/>4:成员保护模式  开启后群成员无法相互添加好友 对应字段 ：private_mode<br/>5：解除用户禁言<br/>6：修改群头像 integer ❤️
     /// accids 设置管理员用户accid拼接，多个使用英文逗号分开<br>解除禁言用户accid，多个使用英文逗号分开 string
     /// accid 指定用户禁言  用户accid string
     case appWahuhighgroupManagegroup(Dictionary<String, Any>)

     // 群搜索
     /// name 群组信息 string ❤️
     case appWahuhighgroupSearchgrouplist(String)

     // 设置/取消群组置顶
     /// groupId 群组tid integer ❤️
     /// type 1：设置指定  2：取消指定 integer ❤️
     case appWahuhighgroupSettop(Int, Int)

     // 高级群扩展功能修改
     /// tid 群组标识 string ❤️
     /// type 操作类型：<br/>2:更新禁止撤回：value：（1：可以撤回；2：不可以撤回）<br/>3:更新自动禁言：value：（1：自动禁言；2：不自动禁言）<br/>4:更新是否允许私聊：value：（允许私聊、不允许私聊）<br/>5:更新是否强提醒：value：（非强提醒、强提醒）<br/>6:更新到期时间：value<br/>7：更新群减员通知：value：（减员不通知、减员通知）<br/>8：更新普通成员是否可以邀请人进群：value（0：管理员;1:所有人） string ❤️
     case appWahuhighgroupUpdateimext(String, String)

     // 处理进群申请
     /// type 操作类型:<br/>2：通过；3：拒绝；4：加入黑名单 ref ❤️
     /// id 申请id integer ❤️
     /// accid 申请用户accid string ❤️
     /// userId 申请用户userId integer ❤️
     /// groupId 申请群组主键 integer ❤️
     /// tid 申请群组tid string ❤️
     case appWajoingrouplistHandlejoingroup(Dictionary<String, Any>)

     // 待处理入群请求数量
     case appWajoingrouplistQueryjoingroupcount

     // 查询入群申请列表
     case appWajoingrouplistQueryjoingrouplist

     // 提交入群申请
     /// tid 群组tid string ❤️
     /// groupId 群组主键id integer ❤️
     /// msg 申请文字 string
     case appWajoingrouplistSubmitjoingroup(Dictionary<String, Any>)

     // 帮助中心列表
     case appWaquestionHelpcenter

     // 帮助中心详情
     /// id 帮助中心标识 integer ❤️
     case appWaquestionHelpcenterdetail(Int)

     // 新增举报
     /// file file array
     /// reportedId 被举报用户/被举报群组 integer ❤️
     /// content 举报类型 string ❤️
     /// type 1：举报用户；2：举报群组 ref ❤️
     /// remark 举报说明 string
     case appWareportAddreportapi(Array<Data>?, Int, String, Int, String?)

     // 获取举报条款
     /// type 1：用户举报类型；2：群组举报类型 ref ❤️
     case appWareportitemGetreportitemlist(Int)

     // 问题反馈
     /// xxxx file array
     /// content 反馈内容 string ❤️
     case appWasuggestAddsuggest(Array<Data>?, String)

}
    

extension MaoLing: TargetType {
    
    public var method: Moya.Method {
        if [].contains(self.path) {
            return .get
        }
        return .post
    }
    
    public var sampleData: Data {
        return "{}".data(using: String.Encoding.utf8)!
    }
    
    public var task: Task {
        var params: [String:Any] = [:]
        var formData: [MultipartFormData] = []
        switch self {
            case .appAppgetserviceinfo:
            break
        case .appAppgetuserinfo(let faccid):
            params["faccid"] = faccid
            break
        case .appCheckmobile(let code):
            params["code"] = code
            break
        case .appCheckpassword(let password):
            params["password"] = password
            break
        case .appGetmyinfo:
            break
        case .appGetsmscode(let mobile):
            params["mobile"] = mobile
            break
        case .appIosversionGetlatestapkinfo:
            break
        case .appLogin(let mobile, let password):
            params["mobile"] = mobile
            params["password"] = password
            break
        case .appLoginbyaccid(let accid):
            params["accid"] = accid
            break
        case .appQunfaauth:
            break
        case .appRegister:
            break
        case .appSearchuserlist(let name, let page, let limit):
            params["name"] = name
            params["page"] = page
            params["limit"] = limit
            break
        case .appTbapkversionGetlatestapkinfo:
            break
        case .appUserinfosetting(let avatar, let operation):
            params["operation"] = operation
            if let data = avatar {
                formData.append(MultipartFormData.init(provider: .data(data), name: "avatar", fileName: nil, mimeType: nil))
            }
            break
        case .appWaaboutusAppqueryaboutus:
            break
        case .appWaagreementGetuseragreement(let type):
            params["type"] = type
            break
        case .appWafavoritemsgAddfavoritemsg(let file, let type, let targetUserAccid):
            params["type"] = type
            params["targetUserAccid"] = targetUserAccid
            if let data = file {
                formData.append(MultipartFormData.init(provider: .data(data), name: "file", fileName: nil, mimeType: nil))
            }
            break
        case .appWafavoritemsgDeletefavoritemsg(let id):
            params["id"] = id
            break
        case .appWafavoritemsgMyfavoritelist(let type):
            params["type"] = type
            break
        case .appWafriendsAppmanagefriends(let param):
            params = params.add(param)
            break
        case .appWafriendsGettopfriends:
            break
        case .appWafriendszoneAddfriendszone(let file, let content):
            params["content"] = content
            file?.forEach { data in
                formData.append(MultipartFormData.init(provider: .data(data), name: "file", fileName: nil, mimeType: nil))
            }
            break
        case .appWafriendszoneAddzonecomment(let zoneId, let content, let targetUserId):
            params["zoneId"] = zoneId
            params["content"] = content
            params["targetUserId"] = targetUserId
            break
        case .appWafriendszoneDeletemyzone(let zoneId):
            params["zoneId"] = zoneId
            break
        case .appWafriendszoneGetmyzonelist(let page, let limit):
            params["page"] = page
            params["limit"] = limit
            break
        case .appWafriendszoneGetzonelist(let page, let limit):
            params["page"] = page
            params["limit"] = limit
            break
        case .appWafriendszoneLikeorcancelzone(let zoneId, let type):
            params["zoneId"] = zoneId
            params["type"] = type
            break
        case .appWafriendszoneQueryzonedetail(let zoneId):
            params["zoneId"] = zoneId
            break
        case .appWahelperHelperlist:
            break
        case .appWahuhighgroupAppgetmutelist(let groupId):
            params["groupId"] = groupId
            break
        case .appWahuhighgroupCreategroupcallback(let tid):
            params["tid"] = tid
            break
        case .appWahuhighgroupCreatenewgroup(let param):
            params = params.add(param)
            break
        case .appWahuhighgroupGettopgroups:
            break
        case .appWahuhighgroupInviteuserbyqrcode(let groupId):
            params["groupId"] = groupId
            break
        case .appWahuhighgroupManagegroup(let param):
            params = params.add(param)
            break
        case .appWahuhighgroupSearchgrouplist(let name):
            params["name"] = name
            break
        case .appWahuhighgroupSettop(let groupId, let type):
            params["groupId"] = groupId
            params["type"] = type
            break
        case .appWahuhighgroupUpdateimext(let tid, let type):
            params["tid"] = tid
            params["type"] = type
            break
        case .appWajoingrouplistHandlejoingroup(let param):
            params = params.add(param)
            break
        case .appWajoingrouplistQueryjoingroupcount:
            break
        case .appWajoingrouplistQueryjoingrouplist:
            break
        case .appWajoingrouplistSubmitjoingroup(let param):
            params = params.add(param)
            break
        case .appWaquestionHelpcenter:
            break
        case .appWaquestionHelpcenterdetail(let id):
            params["id"] = id
            break
        case .appWareportAddreportapi(let file, let reportedId, let content, let type, let remark):
            params["reportedId"] = reportedId
            params["content"] = content
            params["type"] = type
            params["remark"] = remark
            file?.forEach { data in
                formData.append(MultipartFormData.init(provider: .data(data), name: "file", fileName: nil, mimeType: nil))
            }
            break
        case .appWareportitemGetreportitemlist(let type):
            params["type"] = type
            break
        case .appWasuggestAddsuggest(let xxxx, let content):
            params["content"] = content
            xxxx?.forEach { data in
                formData.append(MultipartFormData.init(provider: .data(data), name: "xxxx", fileName: nil, mimeType: nil))
            }
            break
        
        }
        if ["app/userInfoSetting", "app/wafavoritemsg/addFavoriteMsg", "app/wahuhighgroup/createNewGroup", "app/wahuhighgroup/manageGroup"].contains(self.path) {
            return .uploadCompositeMultipart(formData, urlParameters: params)
        }
        return .requestParameters(parameters: params,
                                  encoding: URLEncoding.default)
    }
    
    public var headers: [String : String]? {
        if ["app/userInfoSetting", "app/wafavoritemsg/addFavoriteMsg", "app/wahuhighgroup/createNewGroup", "app/wahuhighgroup/manageGroup"].contains(self.path) {
            return ["Content-type" : "multipart/form-data"]
        }
        return ["Content-type" : "application/json"]
    }
        
    public var baseURL: URL {
        return URL(string: "http://47.96.80.253/suxun/")!
    }
    
    public var path: String {
        switch self {
            
          case .appAppgetserviceinfo:
            return "app/appGetServiceInfo"
        
          case .appAppgetuserinfo:
            return "app/appGetUserInfo"
        
          case .appCheckmobile:
            return "app/checkMobile"
        
          case .appCheckpassword:
            return "app/checkPassword"
        
          case .appGetmyinfo:
            return "app/getMyInfo"
        
          case .appGetsmscode:
            return "app/getSmsCode"
        
          case .appIosversionGetlatestapkinfo:
            return "app/iosversion/getLatestApkInfo"
        
          case .appLogin:
            return "app/login"
        
          case .appLoginbyaccid:
            return "app/loginByAccid"
        
          case .appQunfaauth:
            return "app/qunfaAuth"
        
          case .appRegister:
            return "app/register"
        
          case .appSearchuserlist:
            return "app/searchUserList"
        
          case .appTbapkversionGetlatestapkinfo:
            return "app/tbapkversion/getLatestApkInfo"
        
          case .appUserinfosetting:
            return "app/userInfoSetting"
        
          case .appWaaboutusAppqueryaboutus:
            return "app/waaboutus/appQueryAboutUs"
        
          case .appWaagreementGetuseragreement:
            return "app/waagreement/getUserAgreement"
        
          case .appWafavoritemsgAddfavoritemsg:
            return "app/wafavoritemsg/addFavoriteMsg"
        
          case .appWafavoritemsgDeletefavoritemsg:
            return "app/wafavoritemsg/deleteFavoriteMsg"
        
          case .appWafavoritemsgMyfavoritelist:
            return "app/wafavoritemsg/myFavoriteList"
        
          case .appWafriendsAppmanagefriends:
            return "app/wafriends/appManageFriends"
        
          case .appWafriendsGettopfriends:
            return "app/wafriends/getTopFriends"
        
          case .appWafriendszoneAddfriendszone:
            return "app/wafriendszone/addFriendsZone"
        
          case .appWafriendszoneAddzonecomment:
            return "app/wafriendszone/addZoneComment"
        
          case .appWafriendszoneDeletemyzone:
            return "app/wafriendszone/deleteMyZone"
        
          case .appWafriendszoneGetmyzonelist:
            return "app/wafriendszone/getMyZoneList"
        
          case .appWafriendszoneGetzonelist:
            return "app/wafriendszone/getZoneList"
        
          case .appWafriendszoneLikeorcancelzone:
            return "app/wafriendszone/likeOrCancelZone"
        
          case .appWafriendszoneQueryzonedetail:
            return "app/wafriendszone/queryZoneDetail"
        
          case .appWahelperHelperlist:
            return "app/wahelper/helperList"
        
          case .appWahuhighgroupAppgetmutelist:
            return "app/wahuhighgroup/appGetMuteList"
        
          case .appWahuhighgroupCreategroupcallback:
            return "app/wahuhighgroup/createGroupCallback"
        
          case .appWahuhighgroupCreatenewgroup:
            return "app/wahuhighgroup/createNewGroup"
        
          case .appWahuhighgroupGettopgroups:
            return "app/wahuhighgroup/getTopGroups"
        
          case .appWahuhighgroupInviteuserbyqrcode:
            return "app/wahuhighgroup/inviteUserByQrCode"
        
          case .appWahuhighgroupManagegroup:
            return "app/wahuhighgroup/manageGroup"
        
          case .appWahuhighgroupSearchgrouplist:
            return "app/wahuhighgroup/searchGroupList"
        
          case .appWahuhighgroupSettop:
            return "app/wahuhighgroup/setTop"
        
          case .appWahuhighgroupUpdateimext:
            return "app/wahuhighgroup/updateImExt"
        
          case .appWajoingrouplistHandlejoingroup:
            return "app/wajoingrouplist/handleJoinGroup"
        
          case .appWajoingrouplistQueryjoingroupcount:
            return "app/wajoingrouplist/queryJoinGroupCount"
        
          case .appWajoingrouplistQueryjoingrouplist:
            return "app/wajoingrouplist/queryJoinGroupList"
        
          case .appWajoingrouplistSubmitjoingroup:
            return "app/wajoingrouplist/submitJoinGroup"
        
          case .appWaquestionHelpcenter:
            return "app/waquestion/helpCenter"
        
          case .appWaquestionHelpcenterdetail:
            return "app/waquestion/helpCenterDetail"
        
          case .appWareportAddreportapi:
            return "app/wareport/addReportApi"
        
          case .appWareportitemGetreportitemlist:
            return "app/wareportitem/getReportItemList"
        
          case .appWasuggestAddsuggest:
            return "app/wasuggest/addSuggest"
        }
    }
        
}
